package com.yqkj.zysoft.upms.controller;


import com.project.easy.common.framework.web.controller.BaseController;
import com.project.easy.common.log.annotation.Logging;
import  com.project.easy.common.util.collection.CollectionUtil;
import  com.project.easy.common.util.constants.SysModelConstant;
import  com.project.easy.common.util.constants.VersionConstant;
import  com.project.easy.common.util.dto.IdApiContextParam;
import  com.project.easy.common.util.dto.OneLongApiContextParam;
import  com.project.easy.common.util.dto.PageResDto;
import  com.project.easy.common.util.dto.R;
import  com.project.easy.common.util.dto.TwoApiContextParam;
import com.project.easy.common.framework.web.annotation.ApiValidator;

import com.yqkj.zysoft.upms.entity.FrameworkRole;
import com.yqkj.zysoft.upms.entity.dto.FrameWorkRoleAddRequest;
import com.yqkj.zysoft.upms.entity.dto.FrameWorkRoleUpdateRequest;
import com.yqkj.zysoft.upms.entity.dto.PageRoleRequest;
import com.yqkj.zysoft.upms.service.IFrameworkRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 角色 前端控制器
 * </p>
 *
 * @author GreatorMan.cool
 * @since 2022-08-10
 */
@RestController
@RequestMapping("/api/" + VersionConstant.ONE + "/upms/role")
public class FrameworkRoleController extends BaseController {

    @Autowired
    private IFrameworkRoleService iFrameworkRoleService;

    /**
     * 更新角色的配置
     * @param twoApiContextParam 公参数
     * @return true 成功
     */
    @PostMapping("/updateRoleConfigAuth")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> updateRoleConfigAuth(@RequestBody TwoApiContextParam twoApiContextParam) {
        return R.success(iFrameworkRoleService.updateRoleConfigAuth(twoApiContextParam.getOne(), Long.valueOf(twoApiContextParam.getTwo())));
    }
    /**
     * 获取角色权限
     * @param oneLongApiContextParam 公参数
     * @return 返回权限组
     */
    @PostMapping("/getRoleConfigAuth")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<String> getRoleConfigAuth(@RequestBody OneLongApiContextParam oneLongApiContextParam) {
        return R.success(iFrameworkRoleService.getRoleConfigAuth(oneLongApiContextParam.getKey()));
    }
    /**
     * 新增
     * @param frameWorkRoleAddRequest 参数
     * @return 返回数据
     */
    @PostMapping("/add")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Long> add(@RequestBody FrameWorkRoleAddRequest frameWorkRoleAddRequest) {
        return R.success(iFrameworkRoleService.add(frameWorkRoleAddRequest));
    }
    /**
     * 修改
     * @param frameWorkGroupUpdateRequest 参数
     * @return 返回数据
     */
    @PostMapping("/udpate")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> udpate(@RequestBody FrameWorkRoleUpdateRequest frameWorkGroupUpdateRequest) {
        return R.success(iFrameworkRoleService.updateObject(frameWorkGroupUpdateRequest));
    }
    /**
     * 列表
     * @param pageRoleRequest 参数
     * @return 返回数据
     */
    @PostMapping("/pageList")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<PageResDto<FrameworkRole>> pageList(@RequestBody PageRoleRequest pageRoleRequest) {
        return R.success(iFrameworkRoleService.pageList(pageRoleRequest));
    }
    /**
     * 验证编码
     * @param frameWorkRoleUpdateRequest 参数
     * @return 返回数据
     */
    @PostMapping("/verifyCode")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> verifyCode(@RequestBody FrameWorkRoleUpdateRequest frameWorkRoleUpdateRequest) {
        return R.success(iFrameworkRoleService.verifyCode(frameWorkRoleUpdateRequest));
    }
    /**
     * 删除
     * @param sysParamDto 参数
     * @return 返回数据
     */
    @PostMapping("/del")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> del(@RequestBody IdApiContextParam sysParamDto) {
        return R.success(this.del(iFrameworkRoleService, v -> v::setHasDel,
                CollectionUtil.parseIds(sysParamDto.getIds())));
    }
    /**
     * 禁用
     * @param oneApiContextParam 参数
     * @return 返回数据
     */
    @PostMapping("/disAble")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> disAble(@RequestBody OneLongApiContextParam oneApiContextParam) {
        return R.success(this.iFrameworkRoleService.disAble(oneApiContextParam.getKey()));
    }
    /**
     * 启用
     * @param oneApiContextParam 参数
     * @return 返回数据
     */
    @PostMapping("/able")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> able(@RequestBody OneLongApiContextParam oneApiContextParam) {
        return R.success(this.iFrameworkRoleService.able(oneApiContextParam.getKey()));
    }

}
